@ **************************************************************************
@ * *
@ * Written by flose *
@ * *
@ * A example to make a stack process
@ * *
@ **************************************************************************
.text
.global _start
_start:


	@ initialize Stack porinter
	MOV SP, #0x40000020
MAIN:
	MOV R1, #3
	MOV R2, #5
	BL FUNC1
	ADD R3, R1, R2
	B STOP
	
FUNC1:
	STMFD SP!, {R1-R2, LR}	@ push R1 R2 LR, 保护现场
	MOV R1, #10
	MOV R2, #20
	BL FUNC2
	@ 会重复执行下面三条指令，因为进入FUNC2之后LR会被覆盖成下面这条指令的地址
	SUB R3, R2, R1
	LDMFD SP!, {R1-R2, LR}	@ pop R1 R2 LR, 出栈恢复现场
	MOV PC, LR
	
FUNC2:
	STMFD SP!, {R1-R2, LR}
	MOV R1, #3
	MOV R2, #5
	RSB R3,	R1, R2
	LDMFD SP!, {R1-R2}
	MOV PC, LR
	

STOP:
	B STOP

.end
